<template>
    <el-form ref="form" style="width:400px;" :rules="rules" :model="data" label-width="100px" label-position="right">
        <el-form-item label="角色名称" prop="name">
            <el-input v-model="data.name" style="width:180px"></el-input>
        </el-form-item>
        <el-form-item label="备注">
            <el-input v-model="data.remark" type="textarea" style="width:180px"></el-input>
        </el-form-item>
        <el-form-item style="margin-top: 30px">
            <el-button style="width:120px" type="primary" @click="OnSubmit">保存</el-button>
            <el-button style="width:120px" @click="Hiden">取消</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
import selectBox from '../../../Common/selectBox.vue'
export default {
    components: {
        selectBox: selectBox
    },
    mounted() {
//      this.ajax({
//          url: 'SystemRole/GetNullData?dataType=1',
//          success: function(data) {
//              this.initData = data;
//              if (this.editData != null) {
//                  this.data = this.editData;
//              } else {
//                  this.data = JSON.parse(JSON.stringify(this.initData));
//              }
//          }
//      });
    },
    props: ['editData'],
    data() {
        return {
            data: {},
            rules: {
                name: [{
                    required: true,
                    message: '请输入角色名称',
                    trigger: 'blur'
                }]
            },
            initData: {}
        }
    },
    methods: {
        OnSubmit() {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    let apiAction = this.data.id == null ? "addRole" : "editRole";
                    this.data.inUse=1;
                    this.ajax({
                        url: 'tSysRole/' + apiAction,
                        type: 'post',
                        data: this.data,
                        success: function(data) {
                            this.Hiden();
                            this.$emit("Refresh");
                        }
                    });
                } else {
                    return false;
                }
            });
        },
        Hiden() {
            this.$emit("Show", false);
        },
        ClearData(){
            this.$refs['form'].resetFields();
            this.data = JSON.parse(JSON.stringify(this.initData));
        }
    },
    watch: {
        editData: function(newVal) {
            this.data = newVal;
        }
    }
}
</script>
<style scoped>
	/*.el-dialog--small{
		width: 440px!important;
		height: 314px!important;
	}*/
</style>